-
-
Notifications
You must be signed in to change notification settings - Fork 536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throw an error when using a Union or Interface as an argument type #1222
Conversation
Thanks for adding the Here's a preview of the changelog: This release adds a new exception called import strawberry
@strawberry.type
class Noun:
text: str
@strawberry.type
class Verb:
text: str
Word = strawberry.union("Word", types=(Noun, Verb))
@strawberry.field
def add_word(word: Word) -> bool:
... Here's the preview release card for twitter: Here's the tweet text:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great @MAM-SYS , thank you! I've added some suggested changes.
@jkimbo i appreciate you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good @MAM-SYS ! And your English is very good 😊
I'm going to leave this open for @patrick91 or @BryceBeagle to have a look as well before merging.
RELEASE.md
Outdated
@@ -0,0 +1,21 @@ | |||
Release type: patch | |||
|
|||
This release adds a new exception called `InvalidFieldArgument` which is raised when if a Union or Interface is used as an argument type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This release adds a new exception called `InvalidFieldArgument` which is raised when if a Union or Interface is used as an argument type. | |
This release adds a new exception called `InvalidFieldArgument` which is raised when a Union or Interface is used as an argument type. |
tests/fields/test_arguments.py
Outdated
def test_union_as_an_argument_type(): | ||
with pytest.raises(InvalidFieldArgument): | ||
|
||
@strawberry.type | ||
class Noun: | ||
text: str | ||
|
||
@strawberry.type | ||
class Verb: | ||
text: str | ||
|
||
Word = strawberry.union("Word", types=(Noun, Verb)) | ||
|
||
@strawberry.field | ||
def add_word(word: Word) -> bool: | ||
return True | ||
|
||
|
||
def test_interface_as_an_argument_type(): | ||
with pytest.raises(InvalidFieldArgument): | ||
|
||
@strawberry.interface | ||
class Adjective: | ||
text: str | ||
|
||
@strawberry.field | ||
def add_word(adjective: Adjective) -> bool: | ||
return True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a test that checks it raises in this case too?
@strawberry.interface
class Adjective:
text: str
def add_word(adjective: Adjective) -> bool:
return True
@strawberry.type
class Mutation:
add_word: bool = strawberry.field(resolver=add_word)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, just added a couple of minor comments :)
Codecov Report
@@ Coverage Diff @@
## main #1222 +/- ##
==========================================
+ Coverage 97.56% 97.58% +0.02%
==========================================
Files 88 88
Lines 3321 3358 +37
Branches 477 488 +11
==========================================
+ Hits 3240 3277 +37
Misses 45 45
Partials 36 36 |
Thanks for your help and suggestions again @patrick91 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Thanks for the PR and for pushing the requested changes :D
Thanks for contributing to Strawberry! 🎉 You've been invited to join You can also request a free sticker by filling this form: https://forms.gle/dmnfQUPoY5gZbVT67 And don't forget to join our discord server: https://strawberry.rocks/discord 🔥 |
Hello dear friends @jkimbo @patrick91 @BryceBeagle
This patch is about raising an exception when we use invalid arguments such as Union and Interface. issue #1065
Hope it can help
If anything needs to be changed or fixed, just let me know
With Respect
Description
Types of Changes
Issues Fixed or Closed by This PR
#1065
Checklist